$(function(){
	loadPollingPicture();
	loadArticle();
});

function loadArticle(){
	$.ajax({
		url:BASE_PATH+'/index/all.do',
		type:'get',
		dataType:'json',
		success:function(data){
			createArticle(data);
		}
	});
}

function createArticle(data){
	var html = "";
	if(data){
		for(var title in data){
			if(title != 'nav' && title != 'tag'){
				html+="<div class='row title_bottom'><h3 class='pull-left'>"+data.nav[title].title+"</h3><div class='pull-right more'><a href='"+data.nav[title].url+"'>更多...</a></div> </div>";
				for(var i =0 ; i < data[title].length;i++){
					if(i == data[title].length-1){
						html+="<div class='row title-conatiner-end'> <div class='col-md-3 col-sm-12 title-img hidden-xs'> <a href='"+BASE_PATH+"/article/"+data[title][i].id+".html'><img alt='微儿博客' src='"+BASE_PATH+"/"+data[title][i].thumbnail+"'></a> </div> <div class='col-md-9 col-sm-12  title-content'> <ul> <a href='article/"+data[title][i].id+".html'><h3>"+cutWords(26,data[title][i].title)+"</h3></a> <p>"+cutWords(150,data[title][i].description)+"</p> <p class='title-info'> <span class='tag'>"+createTag(data[title][i].tag,data.tag)+"</span> <span class='time'>"+formateDate(data[title][i].updateTime)+"</span> <span class='comment'></span> <span class='read-count'>阅读("+data[title][i].readCount+")</span> </p> </ul> </div> </div>";
					}else{
						html+="<div class='row title-conatiner'> <div class='col-md-3 col-sm-12 title-img hidden-xs'> <a href='"+BASE_PATH+"/article/"+data[title][i].id+".html'><img alt='微儿博客' src='"+BASE_PATH+"/"+data[title][i].thumbnail+"'></a> </div> <div class='col-md-9 col-sm-12  title-content'> <ul> <a href='article/"+data[title][i].id+".html'><h3>"+cutWords(26,data[title][i].title)+"</h3></a> <p>"+cutWords(150,data[title][i].description)+"</p> <p class='title-info'> <span class='tag'>"+createTag(data[title][i].tag,data.tag)+"</span> <span class='time'>"+formateDate(data[title][i].updateTime)+"</span> <span class='comment'></span> <span class='read-count'>阅读("+data[title][i].readCount+")</span> </p> </ul> </div> </div>";
					}
				}
			}
		}
	}
	$("#article").html(html);
}

function loadPollingPicture(){
	$.ajax({
		url:BASE_PATH+'/index/pic.do',
		type:'get',
		dataType:'json',
		success:function(data){
			createPollingPic(data);
		}
	});
}

function createPollingPic(data){
	var ol = "";
	var item = "";
	if(data){
		for(var i = 0; i < data.length;i++){
			if(i == 0){
				ol+="<li data-target='#myCarousel' data-slide-to='"+i+"' class='active'></li>";
				item+="<div class='item active'><a href='"+data[i].href+"' target='"+data[i].target+"'><img alt='微儿博客' src='"+data[i].imgUrl+"' alt='"+data[i].description+"'></a><div class='carousel-caption'>"+data[i].title+"</div></div>";
			}else{
				ol+="<li data-target='#myCarousel' data-slide-to='"+i+"'></li>";
				item+="<div class='item'><a href='"+data[i].href+"' target='"+data[i].target+"'><img alt='微儿博客' src='"+data[i].imgUrl+"' alt='"+data[i].description+"'></a><div class='carousel-caption'>"+data[i].title+"</div></div>";
			}
		}
		$(".carousel-indicators").html(ol);
		$(".carousel-inner").html(item);
		$('#myCarousel').carousel();
	}
}